/*
 * @Date: 2024-12-17 15:57:35
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2025-02-27 10:28:49
 * @Description: 图例组件的相关实例以及通用方法
 */

import { ref, nextTick, shallowRef } from "vue"


/**
 * 图表hook
 * @param {Object} opts 选项
 * @return {Object}  chartMod: 图例实例对象, chartRef: 图例Ref对象, resizeChart: 图例resize方法
 */
export const useCharts = (opts={}) => {

  // 图例的实力对象
  const chartMod = shallowRef(null)
  // 图例的Ref对象
  const chartRef = ref(null)

  /**
   * 图例resize方法
   * 
   * @param {Number} w 宽
   * @param {Number} h 高
   */
  const resizeChart = (w, h) => {
    nextTick(() => {
      if (!chartMod.value) return
      chartMod.value.resize({ width: `${w}px`, height: `${h}px` })
    })
  }

  return {
    chartMod,
    chartRef,
    resizeChart
  }

}